package IO流;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author:谢君臣
 * @Date:2021/5/23-15:22
 * @version:1.0
 * @function:  线程不安全类
 */
public class SimpleDateFormatTest {

    private static ThreadLocal<SimpleDateFormat> formatThreadLocal = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.SECONDS.sleep(0);
                new Thread(()-> System.out.println(formatThreadLocal.get().format(new Date().getTime())),String.valueOf(i)).start();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
